<?php

namespace Models;

use Phalcon\Mvc\Model\Behavior\SoftDelete;
class AppUser extends BaseModel
{
    const DELETED = '1';

    const NOT_DELETED = '0';
    public function initialize()
    {
        $this->belongsTo("uid", "Models\User", "uid", array('alias' => 'User'));
        $this->belongsTo("appid", "Models\App", "id", array('alias' => 'App'));
        $this->addBehavior(new SoftDelete(
            array(
                'field' => 'del',
                'value' => AppUser::DELETED
            )
        ));
    }

    public function notSave()
    {
        //Obtain the flash service from the DI container
        $flash = $this->getDI()->getFlash();

        //Show validation messages
        foreach ($this->getMessages() as $message) {
            $flash->error($message);
        }
    }

}